package cn.jiadakeji.parent.controller;

import cn.jiadakeji.parent.common.core.controller.BaseController;
import cn.jiadakeji.parent.common.core.domain.AjaxResult;
import cn.jiadakeji.parent.service.CustomerService;
import cn.jiadakeji.parent.vo.LoginVO;
import cn.jiadakeji.parent.vo.PasswordLoginVO;
import cn.jiadakeji.parent.vo.SmsLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author hhaoyu
 */
@Api(value = "登录", tags = {"登录接口"})
@RestController
@RequestMapping("/login")
public class LoginController extends BaseController {


    @Autowired
    private CustomerService customerService;

    @ApiOperation("微信登录")
    @GetMapping("wechatLogin")
    public AjaxResult wechatLogin(@Validated LoginVO loginVO){
        return AjaxResult.success(customerService.wechatLogin(loginVO.getOpenIdCode()));
    }

    @ApiOperation("发送短信验证码")
    @GetMapping("getSmsCode")
    public AjaxResult getSmsCode(@ApiParam("手机号码") @RequestParam String phone){
        return AjaxResult.success(customerService.sendVerifySms(phone));
    }



    @ApiOperation("短信登录")
    @PostMapping("smsLogin")
    public AjaxResult SmsLogin(@Validated @RequestBody SmsLoginVO smsLoginVO){
        return AjaxResult.success(customerService.smsLogin(smsLoginVO));
    }

    @PostMapping("passwordLogin")
    public AjaxResult passwordLogin(@Validated @RequestBody PasswordLoginVO passwordLoginVO){
        return AjaxResult.success(customerService.passwordLogin(passwordLoginVO));
    }

    @ApiOperation("刷新token")
    @GetMapping("refresh")
    public AjaxResult refresh(@RequestParam String refreshToken){
        return AjaxResult.success(customerService.refreshAccessToken(refreshToken));
    }

}
